package com.gitee.shigen.security.util;

import com.alibaba.fastjson.JSON;
import com.gitee.shigen.common.msg.Result;
import org.springframework.http.MediaType;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * @author shigenfu
 * @date 2024/2/26 17:18
 */
public class HttpServletResponseUtil {

    public static void response(HttpServletResponse httpServletResponse, Result<? extends Object> result) throws IOException {
        httpServletResponse.setContentType(MediaType.APPLICATION_JSON_VALUE);
        httpServletResponse.setCharacterEncoding("UTF-8");
        PrintWriter writer = httpServletResponse.getWriter();
        writer.write(JSON.toJSONString(result));
        writer.flush();
    }

}
